<?php

namespace Addons\Forms\Model;

use Think\Model;

/**
 * Forms模型
 */
class FormsModel extends Model
{
    function getInfo($id, $update = false, $data = array())
    {
        $key = 'Forms_getInfo_' . $id;
        $info = S($key);
        if ($info === false || $update) {
            $info = ( array )(empty ($data) ? $this->find($id) : $data);
            S($key, $info, 86400);
        }

        return $info;
    }

    // 素材相关
    function getSucaiList($search = '')
    {
        $map ['token'] = get_token();
        $map ['uid'] = session('mid');
        empty ($search) || $map ['title'] = array(
            'like',
            "%$search%"
        );

        $data_list = $this->where($map)->field('id')->order('id desc')->selectPage();
        foreach ($data_list ['list_data'] as &$v) {
            $data = $this->getInfo($v ['id']);
        }

        return $data_list;
    }

    function getPackageData($id)
    {
        $info = get_token_appinfo();
        $param ['publicid'] = $info ['id'];
        $param ['id'] = $id;

        $data ['forms'] = $this->getInfo($id);

        return $data;
    }
}
